#ifndef LOG_H
#define LOG_H

#ifdef _cplusplus
extern "C" {
#endif

#include <stdio.h> 

#ifndef Log_printf
    #define Log_printf      printf
#endif

void log_init(void);
void logmutex_lock(void);
void logmutex_unlock(void);

#define logerr(format, argument...) do{logmutex_lock(); Log_printf("\033[1;31m[ %s ]  %s (line %d) -> " format"\r\n\033[0m", __FUNCTION__,  __FILE__ ,__LINE__, ##argument );logmutex_unlock(); }while(0)
#define logwarn(format, argument...) do{logmutex_lock(); Log_printf("\033[1;33m[ %s ](line %d) -> " format"\r\n\033[0m", __FUNCTION__, __LINE__, ##argument ); }while(0)

#define logwhite(format, argument...)   do{logmutex_lock(); Log_printf( format,##argument); logmutex_unlock(); }while(0)
#define loggreen(format, argument...)   do{logmutex_lock(); Log_printf("\033[1;32m" format"\r\n\033[0m", ##argument ); logmutex_unlock(); }while(0) 
#define logyellow(format, argument...)  do{logmutex_lock(); Log_printf("\033[1;33m" format"\r\n\033[0m", ##argument ); logmutex_unlock(); }while(0)   
#define logred(format, argument...)     do{logmutex_lock(); Log_printf("\033[1;31m" format"\r\n\033[0m", ##argument ); logmutex_unlock(); }while(0)
#define logblue(format, argument...)     do{logmutex_lock(); Log_printf("\033[1;34m" format"\r\n\033[0m", ##argument ); logmutex_unlock(); }while(0)
#define logpurple(format, argument...)     do{logmutex_lock(); Log_printf("\033[1;35m" format"\r\n\033[0m", ##argument ); logmutex_unlock(); }while(0)
#define loxwhite(buf,len)   do{logmutex_lock();for(uint32_t i=0;i<len;i++)printf("%02x ",((uint8_t*)buf)[i]);printf("\r\n");logmutex_unlock();}while(0)



#ifdef _cplusplus
}
#endif


#endif